# AsyncTool 上传到 Gitee 脚本 (PowerShell)
# 编码: UTF-8

Write-Host "================================================" -ForegroundColor Cyan
Write-Host " AsyncTool 上传到 Gitee" -ForegroundColor Cyan
Write-Host "================================================" -ForegroundColor Cyan
Write-Host ""

# 1. 初始化 Git
Write-Host "[1/6] 初始化 Git 仓库..." -ForegroundColor Yellow
if (-not (Test-Path ".git")) {
    git init
    Write-Host "✓ Git 仓库初始化成功" -ForegroundColor Green
} else {
    Write-Host "✓ Git 仓库已存在" -ForegroundColor Green
}
Write-Host ""

# 2. 配置用户信息
Write-Host "[2/6] 配置 Git 用户信息..." -ForegroundColor Yellow
git config user.name "dixhn"
git config user.email "1828747011@qq.com"
Write-Host "✓ 用户信息配置完成" -ForegroundColor Green
Write-Host ""

# 3. 添加文件
Write-Host "[3/6] 添加所有文件..." -ForegroundColor Yellow
git add .
Write-Host "✓ 文件添加完成" -ForegroundColor Green
Write-Host ""

# 4. 查看状态
Write-Host "[4/6] 查看文件状态..." -ForegroundColor Yellow
git status --short
Write-Host ""

# 5. 提交
Write-Host "[5/6] 提交到本地仓库..." -ForegroundColor Yellow
git commit -m "feat: AsyncTool v1.4.1 - 高性能异步任务编排框架

主要特性:
- DAG 任务依赖管理
- 线程池隔离
- 循环依赖检测
- ID 重复检测
- 优雅关闭
- SLF4J 日志集成

修复和优化:
- 静态线程池覆盖问题
- OOM 风险
- equals/hashCode 错误
- 循环依赖检测优化"

Write-Host "✓ 提交完成" -ForegroundColor Green
Write-Host ""

# 6. 添加远程仓库
Write-Host "[6/6] 配置远程仓库..." -ForegroundColor Yellow
$repoUrl = "https://gitee.com/dixhn/async-tool.git"

git remote remove origin 2>$null
git remote add origin $repoUrl
Write-Host "✓ 远程仓库配置完成" -ForegroundColor Green
Write-Host ""

# 7. 推送
Write-Host "================================================" -ForegroundColor Cyan
Write-Host " 准备推送到 Gitee" -ForegroundColor Cyan
Write-Host "================================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "仓库地址: $repoUrl" -ForegroundColor Yellow
Write-Host ""

$confirm = Read-Host "确认推送？(Y/N)"
if ($confirm -eq "Y" -or $confirm -eq "y") {
    Write-Host "正在推送..." -ForegroundColor Yellow
    
    # 尝试推送到 master
    git push -u origin master 2>&1
    if ($LASTEXITCODE -ne 0) {
        Write-Host "尝试推送到 main 分支..." -ForegroundColor Yellow
        git branch -M main
        git push -u origin main
    }
    
    if ($LASTEXITCODE -eq 0) {
        Write-Host ""
        Write-Host "================================================" -ForegroundColor Green
        Write-Host " ✓ 上传成功！" -ForegroundColor Green
        Write-Host "================================================" -ForegroundColor Green
        Write-Host ""
        Write-Host "访问您的仓库: https://gitee.com/dixhn/async-tool" -ForegroundColor Cyan
    } else {
        Write-Host ""
        Write-Host "推送失败，请检查网络和账号权限" -ForegroundColor Red
    }
} else {
    Write-Host "已取消推送" -ForegroundColor Yellow
}

Write-Host ""
Write-Host "按任意键退出..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

